package com.ruoyi.parttime.service.impl;

import com.ruoyi.common.annotation.AutoFill;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.parttime.Enum.RecruitState;
import com.ruoyi.parttime.domain.ParttimePlaza;
import com.ruoyi.parttime.mapper.ParttimePublishMapper;
import com.ruoyi.parttime.domain.ParttimePublish;
import com.ruoyi.parttime.service.IParttimePublishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;

/**
 * 兼职发布Service业务层处理
 *
 * @author ruoyi
 * @date 2024-04-02
 */
@Service
public class ParttimePublishServiceImpl implements IParttimePublishService {
    @Autowired
    private ParttimePublishMapper parttimePublishMapper;

    /**
     * 查询兼职发布
     *
     * @param id 兼职发布主键
     * @return 兼职发布
     */
    @Override
    public ParttimePublish selectParttimePublishById(Long id) {
        return parttimePublishMapper.selectParttimePublishById(id);
    }

    /**
     * 查询兼职发布列表
     *
     * @param parttimePublish 兼职发布
     * @return 兼职发布
     */
    @Override
    public List<ParttimePublish> selectParttimePublishList(ParttimePublish parttimePublish) {
        //获取当前操作的用户的信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        parttimePublish.setUserId(loginUser.getUserId());
        parttimePublish.setRecruitmentStatus(RecruitState.NORMAL.getRecruitState());
        return parttimePublishMapper.selectParttimePublishList(parttimePublish);
    }

    /**
     * 新增兼职发布
     *
     * @param parttimePublish 兼职发布
     * @return 结果
     */
    @Override
    @AutoFill(value = BusinessType.INSERT)
    public int insertParttimePublish(ParttimePublish parttimePublish) {
        //获取当前操作的用户的信息
        LoginUser loginUser = SecurityUtils.getLoginUser();
        parttimePublish.setUserId(loginUser.getUserId());
        parttimePublish.setUsername(loginUser.getUsername());
        //新插入的兼职信息，默认状态为0:正常
        parttimePublish.setRecruitmentStatus(RecruitState.NORMAL.getRecruitState());
        return parttimePublishMapper.insertParttimePublish(parttimePublish);
    }

    /**
     * 修改兼职发布
     *
     * @param parttimePublish 兼职发布
     * @return 结果
     */
    @Override
    @AutoFill(value = BusinessType.UPDATE)
    public int updateParttimePublish(ParttimePublish parttimePublish) {
//        parttimePublish.setUpdateTime(DateUtils.getNowDate());
        return parttimePublishMapper.updateParttimePublish(parttimePublish);
    }

    /**
     * 批量删除兼职发布
     *
     * @param ids 需要删除的兼职发布主键
     * @return 结果
     */
    @Override
    public int deleteParttimePublishByIds(Long[] ids) {
        return parttimePublishMapper.updateParttimePublishByIds(ids);
    }

    /**
     * 删除兼职发布信息
     *
     * @param id 兼职发布主键
     * @return 结果
     */
    @Override
    public int deleteParttimePublishById(Long id) {
        return parttimePublishMapper.updateParttimePublishById(id);
    }

    /**
     * 批量修改兼职信息
     *
     * @param list
     */
    @Override
    public void batchUpdateParttimePublish(List<ParttimePublish> list) {
        parttimePublishMapper.batchUpdateParttimePublish(list);
    }

    @Override
    public Integer getStatisticsNum() {
        LocalDateTime startTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
        LocalDateTime endTime = LocalDateTime.now();
        return parttimePublishMapper.getStatisticsNum(startTime, endTime);
    }
}
